home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Creative Computers
/
Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso
/
shareware
/
games
/
hextrix
/
hextrix.f
< prev
next >
Wrap
Text File
|
1994-11-17
|
19KB
|
880 lines
\ Hextrix in J-Forth
\ Author: Kasper Østerbye
\ Copyright 1991 Kasper Østerbye
\ Version: 1.0
\
\ This game was written to find out the workings of simple amiga
\ graphics and J-Forth in particular.
\
\ This is give-away-ware. This program is now yours! If you can convince
\ anyone that they should by it, you deserve the profit - I would be
\ interested in knowing though!
\ I am not a poor student, so please do not send 5$ (An amiga 3000
\ would be nice though), but any comments or questions are welcomed.
\ Kasper Østerbye
\ Buderupholmvej 48
\ 9530 Støvring, Denmark
\ email: kasper@iesd.auc.dk
\
\ SPECIAL WARNING FOR THE FOOLS IN USA: Extensive game play can seriously
\ hurt your hand, and you might develop tenosynovitis. There is two
\ things to say about that. 1) It is not my fault, and 2) If you need
\ treatment and cannot affort it, considder whom you give a wote next time!
\ mdh - slight mods to be compatible with new locals (v2.0+) in beta state,
\ everything still works with V2.0 and earlier. Final v2.0+ locals
\ will be completely backward-compatible.
INCLUDE? NewWindow.Setup JU:AMIGA_GRAPH
INCLUDE? ?CLOSEBOX JU:AMIGA_EVENTS
INCLUDE? NewScreen.Setup JU:SCREEN_SUPPORT
INCLUDE? { JU:LOCALS
INCLUDE? EV.GETCLASS JU:AMIGA_EVENTS
INCLUDE? CHOOSE JU:RANDOM
INCLUDE? LOADRGB4() ju:graph_support
INCLUDE? SPRITES JI:GRAPHICS/VIEW.j
INCLUDE? SimpleSprite JI:GRAPHICS/SPRITE.j
INCLUDE? GETSPRITE() JU:SPRITES
INCLUDE? Pieces pieces.f
ANEW TASK-HEXTRIX.f \ added '.f' -- mdh
decimal
\ ******************************************************
\ GAME CONSTANTS
\ ******************************************************
1 Constant bordercolor
13 constant borderwidth \ should be odd to look good
23 constant borderheight
\ *****************************************************************
\ SCREEN AND WINDOW
\ *****************************************************************
\ Declare necessary Amiga 'C' structures.
NewScreen GameNewScreen
NewWindow GameNewWindow
VARIABLE Game-SCREEN
create aColorTable
hex
000 w, ccc w, 0d0 w, fff w,
f00 w, 0dd w, d0d w, 888 w,
a60 w, 00f w, fd0 w, fca w,
a60 w, 00f w, fd0 w, fca w, \ This last line is not used
000 w, ccc w, 0d0 w, fff w, \ And all this is just the same as
f00 w, 0dd w, d0d w, 888 w, \ the 4 lines above
a60 w, 00f w, fd0 w, fca w,
a60 w, 00f w, fd0 w, fca w,
decimal
: CLOSE.Game.SCREEN ( -- , CLose demo screen )
game-screen @ closescreen()
;
: OPEN.Game.SCREEN ( -- screen | NULL )
\ Set to default values.
GameNewScreen NewScreen.Setup
GameNewWindow NewWindow.Setup
\
\ Modify defaults for this demo.
HIRES ( LACE | ) SPRITES | GameNewScreen ..! ns_viewmodes
640 GameNewScreen ..! ns_width
210 GameNewScreen ..! ns_height
4 GameNewScreen ..! ns_depth ( 16 colors )
0" HexTrix by Kasper Østerbye" >abs
GameNewScreen ..! ns_DefaultTitle
\ Open Screen and store pointer in NewWindow structure.
GameNewScreen openscreen() dup Game-Screen ! ( Open screen. )
\ Sometimes the Amiga can build a bad COPPER list for screens.
\ This can happen if you have Emacs and Workbench up in INTERLACE
\ mode and open a NON-INTERLACE screen.
\ The following calls will correct this problem (hopefully).
dup
IF game-screen @ screentoback()
RemakeDisplay()
game-screen @ screentofront()
game-screen @ .. sc_viewport aColorTable 32 loadRGB4()
THEN
;
\ Check for proper opening.
: OPEN.Game.WINDOW ( screen -- window | NULL )
>abs GameNewWindow ..! nw_screen
\ Set up window.
CUSTOMSCREEN GameNewWindow ..! nw_type
VANILLAKEY CLOSEWINDOW | INTUITICKS | GameNewWindow ..! nw_idcmpflags
0" HexTrix in JFORTH -- By Kasper Østerbye" >abs GameNewWindow ..! nw_Title
0 GameNewWindow ..! nw_TopEdge
600 GameNewWindow ..! nw_Width
210 GameNewWindow ..! nw_Height
GameNewWindow gr.opencurw
;
\ ******************************************************
\
\ sprites used for moving pieces
\
\ ******************************************************
VARIABLE usingSprites
SimpleSprite Sprite-0
SimpleSprite Sprite-1
SimpleSprite Sprite-2
SimpleSprite Sprite-3
2 CONSTANT spriteNumberOffset
: SpriteArray ( index -- spriteaddr )
CASE
0 OF Sprite-0 ENDOF
1 OF Sprite-1 ENDOF
2 OF Sprite-2 ENDOF
3 OF Sprite-3 ENDOF
ENDCASE
;
: OPEN.SPRITES ( -- )
4 0
DO
i spriteArray i spriteNumberOffset + ( we reserve sprites 2,3,4,5 )
getSprite()
-1 = ?abort" OPEN.SPRITE - Sprite could not be allocated!"
0 i spriteArray ..! ss_x
0 i spriteArray ..! ss_y
7 i spriteArray ..! ss_height
LOOP
;
\ Build sprite data, sprites are two planes deep.
2 base ! ( Use binary to see which bits are on. )
CREATE SPRITE-DATA
here
0 w, 0 w, ( position control, used by system. )
\ Plane0 Plane1
0001,1111,0000,0000 W, 0001,1111,0000,0000 W,
0011,1111,1000,0000 W, 0011,1111,1000,0000 W,
0111,1111,1100,0000 W, 0111,1111,1100,0000 W,
1111,1111,1110,0000 W, 1111,1111,1110,0000 W,
0111,1111,1100,0000 W, 0111,1111,1100,0000 W,
0011,1111,1000,0000 W, 0011,1111,1000,0000 W,
0001,1111,0000,0000 W, 0001,1111,0000,0000 W,
0 W, 0 W, ( unattached simple sprite. )
here swap - constant SPRITE_DATA_SIZE
decimal
4 ARRAY Sprite-data-ptrs ( point to ALLOCed CHIP RAM copy )
: CHANGE.SPRITES
\ Allocate CHIP memory and copy sprite to it.
\ AMIGAs with more than 512K RAM might be running
\ JForth in FAST RAM. We could NOT, therefore, use
\ the SPRITE-DATA directly since it would be inaccessable
\ to the graphics coprocessors.
4 0
DO
MEMF_CHIP sprite_data_size allocblock ?dup
IF
dup i sprite-data-ptrs ! ( save memory pointer )
sprite-data swap sprite_data_size cmove ( copy )
game-screen @ dup IF .. sc_viewport THEN
i spriteArray i sprite-data-ptrs @ ChangeSprite()
ELSE
." Unable to allocate all sprites" abort
THEN
LOOP
;
: FREE.SPRITES
4 0
DO
i spriteNumberOffset + freesprite()
i sprite-data-ptrs @ freeblock
LOOP
;
\ *********************************************************************
\ Misc stuff to go elsewhere later
\ *********************************************************************
: GVP ( --- relAddr , gameViewPort )
game-screen @ .. sc_viewport
;
: setRGB4() ( viewPort penNr R G B )
callvoid>abs graphics_lib setRGB4
;
: SetSpriteColors { penNr -- } \ had to add '--' mdh
gvp 23 penNr aColorTable ctable>rgb setRGB4()
gvp 27 penNr aColorTable ctable>rgb setRGB4()
;
: MoveSprite { x y spr# -- } \ had to add '--' mdh
\ move sprite to screen coordinate x,y
\ take spriteNumberOffset and hires mode into account
gvp spr# spriteArray x 2+ y moveSprite()
;
: HideSprites
0 setSpriteColors
4 0 do 30 30 i MoveSprite loop
;
\ ******************************************************
\
\ misc utilities
\
\ ******************************************************
: p+ { x y x' y' -- x' y' } ( add the points ) \ changed --> to -- mdh
x x' + \ commented out mdh -> x'
y y' + \ commented out mdh -> y'
;
: p-right { c r -- c r } ( right-point )
c 1+ -> c
c 1 and IF ELSE r 1+ -> r THEN
c r \ added mdh
;
: p-left { c r -- c r } ( left-point )
c 1- -> c
c 1 and IF r 1- -> r THEN
c r \ added mdh
;
: hex>rect ( c r --> c' r' )
over 2/ -
;
: rect>hex ( c r --> c' r' )
over 2/ +
;
\ **********************************************************
\ INTERNAL BOARD (IB)
\ **********************************************************
borderWidth borderHeight * carray ib ( Internal Board )
: clearIb
0 ib borderWidth borderHeight * erase
;
: getIb ( c r --> byte )
swap borderHeight * + ib c@
;
: putIb ( byte c r --> , store byte )
swap borderHeight * + ib c!
;
: isIbEmpty? ( hex-c hex-r --> bool )
getIb 0=
;
: .Ib
borderHeight 0
DO i 4 .r
borderWidth 0
DO
i j getIb 2 .r
LOOP